#!/usr/bin/env node

const { EventEmitter } = require("events");



class Dog extends EventEmitter {
    //公有
    constructor(name,energy) {
        super();
        this.#name = name;
        this.#energy = energy;
        this.#start();//调用私有
    }
    get name() {return this.#name};
    get energy() {return this.#energy};   
    set energy(e) {//判断负数
        this.#energy = e;
        this.#start();//重用
    }


    //私有
    #start() {
        let timer = setInterval(()=>{
            this.emit('bark');
            this.#energy--;
            if(this.#energy <= 0)
                clearInterval(timer);
        },1000)
    }
    #name = '';
    #energy = 0;
}

module.exports = Dog;